package com.kehutong.charge.admin;

import com.kehutong.charge.entity.MeterReading;
import com.kehutong.charge.service.MeterReadService;
import com.kehutong.common.util.Token;
import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: kht
 * @description: 抄表管理，包括水表、电表、天然气表
 * @author: joneron
 * @create: 2021/7/22
 **/
@MvcAction
@ReqMapping("/admin/pay/charge/meter/reading")
public class MeterReadManageController {

    @Inject
    MeterReadService meterReadService;

    @ReqMapping("/page")
    @HasPermission("pay:charge:meter:reading:view")
    public Object page(JSONObject jsonObject) throws Exception {
        return meterReadService.findPage(jsonObject);
    }


    @ReqMapping("/template/export")
    @HasPermission("pay:charge:meter:reading:view")
    public void templateExport(HttpServletRequest req, HttpServletResponse resp,String meterTypeNo){
        meterReadService.templateExport(req,resp,meterTypeNo);
    }


    @ReqMapping("/page/export")
    @HasPermission("pay:charge:meter:reading:view")
    public void pageExport(HttpServletRequest req, HttpServletResponse resp,JSONObject jsonObject){
        meterReadService.pageExport(req,resp,jsonObject);
    }


    /**
     * 抄表列表导入检查
     * @param jsonObject
     */
    @ReqMapping("/list/import/check")
    public Object importExcelCheck(JSONObject jsonObject){
        meterReadService.importExcelCheck(jsonObject);
        return Result.success();
    }


    /**
     * @Author jian Ye
     * 抄表列表导入
     * @param jsonObject
     */
    @ReqMapping("/list/import")
    @HasPermission("pay:charge:meter:reading:edit")
    public Object listImport(JSONObject jsonObject, Token token) throws Exception {
        return meterReadService.listImport(jsonObject,token);
    }


    @ReqMapping("/findReadStatist")
    @HasPermission("pay:charge:meter:reading:view")
    public Object findReadStatist(JSONObject jsonObject) throws Exception {
        return meterReadService.findReadStatist(jsonObject);
    }


    @ReqMapping("/findReadStatist/export")
    @HasPermission("pay:charge:meter:reading:view")
    public void findReadStatistExport(HttpServletRequest req, HttpServletResponse resp,JSONObject jsonObject){
        meterReadService.findReadStatistExport(req,resp,jsonObject);
    }


    @ReqMapping("/list")
    @HasPermission("pay:charge:meter:reading:view")
    public Object list(JSONObject jsonObject) {
        return meterReadService.findList(jsonObject);
    }


    @Bean(newInstance=true, copy=true)
    @HasPermission("pay:charge:meter:reading:edit")
    @ReqMapping("/save")
    public Object save(MeterReading entity, Token token) throws Exception {
        return meterReadService.save(entity,token);
    }

    @Bean(copy=true)
    @HasPermission("pay:charge:meter:reading:edit")
    @ReqMapping("/update")
    public Object update(MeterReading entity) throws Exception {

        return meterReadService.update(entity);
    }

    @HasPermission("pay:charge:meter:reading:edit")
    @ReqMapping("/delete")
    public Object delete(MeterReading entity) {

        return meterReadService.deleteById(entity.getId());
    }

    @ReqMapping("/get")
    public Object get(MeterReading entity) {

        return Result.success(entity);
    }

    @ReqMapping("/getObj")
    public Object getObj(JSONObject jsonObject) {

        return meterReadService.getObj(jsonObject);
    }

    @HasPermission("pay:charge:meter:reading:view")
    @ReqMapping("/statist")
    public Object statist(JSONObject jsonObject,Token token) throws Exception {

        return meterReadService.findStatist(jsonObject,token);
    }


    /**
     * 抄表
     * @param jsonObject
     * @param token
     * @return
     * @throws Exception
     */
    @HasPermission("pay:charge:meter:reading:view")
    @ReqMapping("/statist/export")
    public void statistExport(HttpServletRequest req , HttpServletResponse resp, JSONObject jsonObject, Token token) throws Exception {
        meterReadService.statistExport(req, resp,jsonObject,token);
    }


    /**
     * 批量逻辑删除
     */
    @HasPermission("pay:charge:meter:reading:edit")
    @ReqMapping("/batch/delete")
    public Object batchDelete(Token token, JSONObject jsonObject) {

        return Result.success(meterReadService.batchDelete(jsonObject));
    }


    /**
     * 抄表 费用信息获取（阶梯价、单价、一口价等）
     */
    @HasPermission("pay:charge:meter:reading:view")
    @ReqMapping("/fee/settle/detail")
    public void feeSettleDetail(JSONObject jsonObject, Token token){
        meterReadService.feeSettleDetail(jsonObject,token);
    }
}
